#include<bits/stdc++.h>
using namespace std;
int n,a[5010],dp[5010][5010],pos[10],ans,jl[10];
const int mod=998244353;
void dfs(int u){
	if(u>n){
		int ok=1;
		for(int i=1;i<=n;i++){
			int l=pos[jl[i]],r=i;
			if(l>r) swap(l,r);
			for(int j=l;j<=r;j++)
				if(a[j]>jl[i]||jl[j]<jl[i]) ok=0;
		}
		ans+=ok,ans%=mod;
		return;
	}
	for(int i=1;i<=n;i++){
		jl[u]=i;
		dfs(u+1);
	}
}
int main(){
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		pos[a[i]]=i;
	}
	if(n<=8){
		dfs(1);
		printf("%d",ans);
	}else{
		for(int i=1;i<=n;i++)
			dp[1][i]=1;
		for(int i=2;i<=n;i++){
			for(int j=1;j<=i;j++)
				dp[i][i]+=dp[i-1][j],dp[i][i]%=mod;
			for(int j=i+1;j<=n;j++)
				dp[i][j]=dp[i][j-1]+dp[i-1][j],dp[i][j]%=mod;
		}
		printf("%d",dp[n][n]);
	}
	return 0;
}
